/* SQUIB - Scala's Quirky User Interface Builder 
    Copyright (C) 2008 Tim Dalton

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
*/

import java.awt.{GridBagConstraints}

import scala.collection.mutable.{HashMap}

package tfd.scala.squib {

    object gridbagconstraints {
        private def populateFields(gbc:GridBagConstraints, content: Seq[Tuple2[Symbol,AnyVal]]) = {
            for (c <- content.elements) {
                if (c._1 != null) {
                    // Might replace this with some doing introspection like doSetters
                    if (c._1.equals('fill)) gbc.fill = c._2.asInstanceOf[int]
                    if (c._1.equals('weightx)) gbc.weightx = c._2.asInstanceOf[double]
                    if (c._1.equals('weighty)) gbc.weighty = c._2.asInstanceOf[double]
                    if (c._1.equals('gridwidth)) gbc.gridwidth = c._2.asInstanceOf[int]
                    if (c._1.equals('gridheight)) gbc.gridheight = c._2.asInstanceOf[int]
                    if (c._1.equals('gridx)) gbc.gridx = c._2.asInstanceOf[int]
                    if (c._1.equals('gridy)) gbc.gridy = c._2.asInstanceOf[int]
                } 
            }
            gbc
        }
        
        def apply(gbc:GridBagConstraints, content: Tuple2[Symbol,AnyVal]*):GridBagConstraints = {
            populateFields(gbc.clone().asInstanceOf[GridBagConstraints], content)
        }
        
        def apply(content: Tuple2[Symbol,AnyVal]*):GridBagConstraints = {
            val gbc = new GridBagConstraints()
            populateFields(gbc.asInstanceOf[GridBagConstraints], content)
        }
    }
}
